home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 2010 April / PCWorld0410.iso / hity wydania / Ubuntu 9.10 PL / karmelkowy-koliberek-desktop-9.10-i386-PL.iso / casper / filesystem.squashfs / usr / share / hplip / plugin.pyc (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2009-10-28  |  11.5 KB  |  281 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.6)
  3.  
  4. __version__ = '2.1'
  5. __mod__ = 'hp-plugin'
  6. __title__ = 'Plugin Download and Install Utility'
  7. __doc__ = ''
  8. import sys
  9. import getopt
  10. import time
  11. import os.path as os
  12. import re
  13. import os
  14. import gzip
  15. from base.g import *
  16. from base import device, utils, tui, module
  17. from prnt import cups
  18. pm = None
  19.  
  20. def plugin_download_callback(c, s, t):
  21.     pm.update(int(100 * c * s / t), utils.format_bytes(c * s))
  22.  
  23.  
  24. def plugin_install_callback(s):
  25.     print s
  26.  
  27. USAGE = [
  28.     (__doc__, '', 'name', True),
  29.     ('Usage: %s [MODE] [OPTIONS]' % __mod__, '', 'summary', True),
  30.     utils.USAGE_MODE,
  31.     utils.USAGE_GUI_MODE,
  32.     utils.USAGE_INTERACTIVE_MODE,
  33.     ('Installation for required printer mode:', '--required (Qt4 only)', 'option', False),
  34.     ('Installation for optional printer mode:', '--optional (Qt4 only)', 'option', False),
  35.     utils.USAGE_LANGUAGE,
  36.     utils.USAGE_OPTIONS,
  37.     ('Specify the path to the plugin file:', '-p <path> or --path=<path> or --plugin=<path>', 'option', False),
  38.     utils.USAGE_LOGGING1,
  39.     utils.USAGE_LOGGING2,
  40.     utils.USAGE_LOGGING3,
  41.     utils.USAGE_HELP,
  42.     utils.USAGE_SPACE,
  43.     utils.USAGE_SEEALSO,
  44.     ('hp-setup', '', 'seealso', False),
  45.     ('hp-firmware', '', 'seealso', False)]
  46. mod = module.Module(__mod__, __title__, __version__, __doc__, USAGE, (INTERACTIVE_MODE, GUI_MODE), (UI_TOOLKIT_QT3, UI_TOOLKIT_QT4), True)
  47. (opts, device_uri, printer_name, mode, ui_toolkit, loc) = mod.parseStdOpts('p:', [
  48.     'path=',
  49.     'plugin=',
  50.     'plug-in=',
  51.     'reason=',
  52.     'generic',
  53.     'optional',
  54.     'required'], handle_device_printer = False)
  55. plugin_path = None
  56. install_mode = PLUGIN_NONE
  57. plugin_reason = PLUGIN_REASON_NONE
  58. for o, a in opts:
  59.     if o in ('-p', '--path', '--plugin', '--plug-in'):
  60.         plugin_path = os.path.normpath(os.path.abspath(os.path.expanduser(a)))
  61.         continue
  62.     if o == '--required':
  63.         install_mode = PLUGIN_REQUIRED
  64.         if ui_toolkit == 'qt3':
  65.             log.warn('--required switch ignored.')
  66.         
  67.     ui_toolkit == 'qt3'
  68.     if o == '--optional':
  69.         install_mode = PLUGIN_OPTIONAL
  70.         if ui_toolkit == 'qt3':
  71.             log.warn('--optional switch ignored.')
  72.         
  73.     ui_toolkit == 'qt3'
  74.     if o == '--reason':
  75.         plugin_reason = int(a)
  76.         continue
  77.  
  78. version = prop.installed_version
  79. plugin_filename = 'hplip-%s-plugin.run' % version
  80. if plugin_path is not None:
  81.     if not os.path.exists(plugin_path):
  82.         log.error("Plug-in path '%s' not found." % plugin_path)
  83.         sys.exit(1)
  84.     
  85.     if os.path.isdir(plugin_path):
  86.         plugin_path = os.path.join(plugin_path, 'hplip-%s-plugin.run' % version)
  87.         if not os.path.exists(plugin_path):
  88.             log.error("Plug-in path '%s' not found." % plugin_path)
  89.             sys.exit(1)
  90.         
  91.     
  92.     if os.path.basename(plugin_path) != plugin_filename:
  93.         log.error("Plug-in filename must be '%s'." % plugin_filename)
  94.         sys.exit(1)
  95.     
  96.     size = os.stat(plugin_path)[6]
  97.     checksum = ''
  98.     timestamp = 0
  99.     plugin_path = 'file://' + plugin_path
  100.     log.debug('Plugin path=%s (%d)' % (plugin_path, size))
  101.  
  102. if mode == GUI_MODE:
  103.     if ui_toolkit == 'qt3':
  104.         if not utils.canEnterGUIMode():
  105.             log.error('%s requires GUI support (try running with --qt4). Try using interactive (-i) mode.' % __mod__)
  106.             sys.exit(1)
  107.         
  108.     elif not utils.canEnterGUIMode4():
  109.         log.error('%s requires GUI support (try running with --qt3). Try using interactive (-i) mode.' % __mod__)
  110.         sys.exit(1)
  111.     
  112.  
  113. PKIT = utils.to_bool(sys_conf.get('configure', 'policy-kit'))
  114. if PKIT:
  115.     
  116.     try:
  117.         from base.pkit import *
  118.         
  119.         try:
  120.             pkit = PolicyKit()
  121.             pkit_installed = True
  122.         except dbus.DBusException:
  123.             ex = None
  124.             log.error('PolicyKit support requires DBUS or PolicyKit support files missing')
  125.             pkit_installed = False
  126.  
  127.     log.error('Unable to load pkit...is HPLIP installed?')
  128.     pkit_installed = False
  129.  
  130. else:
  131.     pkit_installed = False
  132. if mode == GUI_MODE:
  133.     pass
  134. None if ui_toolkit == 'qt3' else None<EXCEPTION MATCH>KeyboardInterrupt
  135.  
  136. try:
  137.     if not os.geteuid() == 0:
  138.         log.error('You must be root to run this utility.')
  139.         sys.exit(1)
  140.     
  141.     log.info("(Note: Defaults for each question are maked with a '*'. Press <enter> to accept the default.)")
  142.     log.info('')
  143.     from installer import core_install
  144.     core = core_install.CoreInstall()
  145.     core.set_plugin_version()
  146.     tui.header('PLUG-IN INSTALLATION FOR HPLIP %s' % version)
  147.     if core.check_for_plugin() and plugin_path is None:
  148.         log.info('The driver plugin for HPLIP %s appears to already be installed.' % version)
  149.         (cont, ans) = tui.enter_yes_no('Do you wish to download and re-install the plug-in?')
  150.         if not cont or not ans:
  151.             sys.exit(0)
  152.         
  153.     
  154.     if plugin_path is None:
  155.         table = tui.Formatter(header = ('Option', 'Description'), min_widths = (10, 50))
  156.         table.add(('d', 'Download plug-in from HP (recomended)'))
  157.         table.add(('p', 'Specify a path to the plug-in (advanced)'))
  158.         table.add(('q', 'Quit hp-plugin (skip installation)'))
  159.         table.output()
  160.         (cont, ans) = tui.enter_choice('\nEnter option (d=download*, p=specify path, q=quit) ? ', [
  161.             'd',
  162.             'p'], 'd')
  163.         if not cont:
  164.             sys.exit(0)
  165.         
  166.         if ans == 'd':
  167.             plugin_conf_url = core.get_plugin_conf_url()
  168.             if plugin_conf_url.startswith('file://'):
  169.                 tui.header('COPY CONFIGURATION')
  170.             else:
  171.                 tui.header('DOWNLOAD CONFIGURATION')
  172.                 log.info('Checking for network connection...')
  173.                 ok = core.check_network_connection()
  174.                 if not ok:
  175.                     log.error('Network connection not detected.')
  176.                     sys.exit(1)
  177.                 
  178.             log.info('Downloading configuration file from: %s' % plugin_conf_url)
  179.             pm = tui.ProgressMeter('Downloading configuration:')
  180.             (plugin_path, size, checksum, timestamp, ok) = core.get_plugin_info(plugin_conf_url, plugin_download_callback)
  181.             print 
  182.             if not plugin_path.startswith('http://') and not plugin_path.startswith('file://'):
  183.                 plugin_path = 'file://' + plugin_path
  184.             
  185.         else:
  186.             while True:
  187.                 plugin_path = raw_input(log.bold("Enter the path to the 'hplip-%s-plugin.run' file (q=quit) : " % version)).strip()
  188.                 if plugin_path.strip().lower() == 'q':
  189.                     sys.exit(1)
  190.                 
  191.                 if not plugin_path.startswith('http://'):
  192.                     plugin_path = os.path.normpath(os.path.abspath(os.path.expanduser(plugin_path)))
  193.                     if not os.path.exists(plugin_path):
  194.                         log.error("Plug-in path '%s' not found." % plugin_path)
  195.                         continue
  196.                     
  197.                     if os.path.isdir(plugin_path):
  198.                         plugin_path = os.path.join(plugin_path, plugin_filename)
  199.                         if not os.path.exists(plugin_path):
  200.                             log.error("Plug-in path '%s' not found." % plugin_path)
  201.                             continue
  202.                         
  203.                     
  204.                     if os.path.basename(plugin_path) != plugin_filename:
  205.                         log.error("Plug-in filename must be '%s'." % plugin_filename)
  206.                         continue
  207.                     
  208.                     size = os.stat(plugin_path)[6]
  209.                     checksum = ''
  210.                     timestamp = 0
  211.                     plugin_path = 'file://' + plugin_path
  212.                 
  213.                 break
  214.     
  215.     if plugin_path.startswith('file://'):
  216.         tui.header('COPY PLUGIN')
  217.     else:
  218.         tui.header('DOWNLOAD PLUGIN')
  219.         log.info('Checking for network connection...')
  220.         ok = core.check_network_connection()
  221.         if not ok:
  222.             log.error('Network connection not detected.')
  223.             sys.exit(1)
  224.         
  225.     log.info('Downloading plug-in from: %s' % plugin_path)
  226.     pm = tui.ProgressMeter('Downloading plug-in:')
  227.     (status, ret) = core.download_plugin(plugin_path, size, checksum, timestamp, plugin_download_callback)
  228.     print 
  229.     if status in (core_install.PLUGIN_INSTALL_ERROR_UNABLE_TO_RECV_KEYS, core_install.PLUGIN_INSTALL_ERROR_DIGITAL_SIG_NOT_FOUND):
  230.         log.error('Digital signature file download failed. Without this file, it is not possible to authenticate and validate the plug-in prior to installation.')
  231.         (cont, ans) = tui.enter_yes_no('Do you still want to install the plug-in?', 'n')
  232.         if not cont or not ans:
  233.             sys.exit(0)
  234.         
  235.     elif status != core_install.PLUGIN_INSTALL_ERROR_NONE:
  236.         if status == core_install.PLUGIN_INSTALL_ERROR_PLUGIN_FILE_NOT_FOUND:
  237.             desc = 'Plug-in file not found (server returned 404 or similar error). Error code: %s' % str(ret)
  238.         elif status == core_install.PLUGIN_INSTALL_ERROR_DIGITAL_SIG_BAD:
  239.             desc = 'Plug-in file does not match its digital signature. File may have been corrupted or altered. Error code: %s' % str(ret)
  240.         elif status == core_install.PLUGIN_INSTALL_ERROR_PLUGIN_FILE_CHECKSUM_ERROR:
  241.             desc = 'Plug-in file does not match its checksum. File may have been corrupted or altered.'
  242.         elif status == core_install.PLUGIN_INSTALL_ERROR_NO_NETWORK:
  243.             desc = 'Unable to connect to network to download the plug-in. Please check your network connection and try again.'
  244.         elif status == core_install.PLUGIN_INSTALL_ERROR_DIRECTORY_ERROR:
  245.             desc = 'Unable to create the plug-in directory. Please check your permissions and try again.'
  246.         
  247.         core.delete_plugin()
  248.         log.error(desc)
  249.         sys.exit(1)
  250.     
  251.     tui.header('INSTALLING PLUG-IN')
  252.     core.run_plugin(mode, plugin_install_callback)
  253.     cups_devices = device.getSupportedCUPSDevices([
  254.         'hp'])
  255.     title = False
  256.     for dev in cups_devices:
  257.         mq = device.queryModelByURI(dev)
  258.         if mq.get('fw-download', 0):
  259.             if not title:
  260.                 tui.header('DOWNLOADING FIRMWARE')
  261.                 title = True
  262.             
  263.             log.info(log.bold('\nDownloading firmware to device %s...' % dev))
  264.             
  265.             try:
  266.                 d = device.Device(dev)
  267.             except Error:
  268.                 log.error('Error opening device. Exiting.')
  269.                 sys.exit(1)
  270.  
  271.             if d.downloadFirmware():
  272.                 log.info('Firmware download successful.\n')
  273.             
  274.             d.close()
  275.             continue
  276. except KeyboardInterrupt:
  277.     log.error('User exit')
  278.  
  279. log.info('')
  280. log.info('Done.')
  281.